/**
 * Company : Thai Informatic System Co., Ltd.
 * Created By : Chatree Siangklom
 * Created On : Apr 3, 2013  9:06:32 AM 
 * e-Mail : dr_chatree@hotmail.com
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : promis.api.oracle
 * File Name : TableServices.java
 * TODO
 */
package promis.api.oracle;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import promis.db.connection.dbHelper;
import promis.utility.Utilitys;

/**
 * @author chatree
 *
 */
public class TableServices {
	
	
	public boolean TableExists(String owner, String table_name) throws Exception {
		Connection conn = new dbHelper().getConn();
		try{
			
			String sql ="SELECT TABLE_NAME FROM ALL_TAB_COLUMNS  WHERE OWNER = "+ Utilitys.strSql(owner).toUpperCase() +"  AND TABLE_NAME = "+ Utilitys.strSql(table_name).toUpperCase() +"  ";			
			System.out.println(sql);
						
			conn.setAutoCommit(true);
			Statement stmt =  conn.createStatement();
			ResultSet rs = stmt.executeQuery(sql);
			while(rs.next()){
				return true;
			}
		}catch(Exception e){
			e.printStackTrace();
			throw e;
		}finally{
			if(!conn.isClosed())
				conn.close();
			
			conn = null;
		}
		return false;
	}

}
